﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace ADECMS
{
    /// <summary>
    /// Summary description for SlidesService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
     [System.Web.Script.Services.ScriptService]
    public class SlidesService : System.Web.Services.WebService
    {

        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public AjaxControlToolkit.Slide[] GetSlides(string contextKey)
        {
            // contextKey nije prazan
            if (String.IsNullOrEmpty(contextKey))
                return null;

            string filepath = HttpContext.Current.Server.MapPath("/Uploads/Files/" + Path.GetFileNameWithoutExtension(contextKey) + "/");
            System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(filepath);
            string[] fajlovi = Directory.GetFiles(filepath);
            int nFajlovi = dInfo.GetFiles().GetUpperBound(0)+1;
            AjaxControlToolkit.Slide[] Slides = new AjaxControlToolkit.Slide[nFajlovi];
            int i = 0;
            foreach(string f in fajlovi){
               Slides[i] = new AjaxControlToolkit.Slide(f,Path.GetFileName(f),Path.GetFileName(f));
               i++;
            }

            return Slides;
        }
    }
}
